package Util;

import Semantic.CodeGenerator;

public class FunctionsLibrary {
	
	public void writeIOFunctions(CodeGenerator codeGen){
		
		codeGen.setLabel("HIGH_BYTE");
		codeGen.writeVariable("K", "/0");
		codeGen.setLabel("LOW_BYTE");
		codeGen.writeVariable("K", "/0");
		codeGen.setLabel("CONVERTED_VALUE");
		codeGen.writeVariable("K", "/0");
		codeGen.setLabel("IS_NEGATIVE");
		codeGen.writeVariable("K", "/0");
		codeGen.setLabel("BYTE_READ");
		codeGen.writeVariable("K", "/0");
		codeGen.setLabel("MINUS_CHAR");
		codeGen.writeVariable("K", "/2D");
		codeGen.setLabel("SHIFT_TWO");
		codeGen.writeVariable("K", "/100");
		codeGen.setLabel("MVN_READ");
		codeGen.writeInstruction("K", "/0000");
		codeGen.writeInstruction("LV","=0");
		codeGen.writeInstruction("MM","CONVERTED_VALUE");
		codeGen.writeInstruction("LV","=0");
		codeGen.writeInstruction("MM","IS_NEGATIVE");
		codeGen.writeInstruction("GD","/0000");
		codeGen.writeInstruction("MM","BYTE_READ");
		codeGen.writeInstruction("SC","SPLIT_WORD");
		codeGen.writeInstruction("LD","HIGH_BYTE");
		codeGen.writeInstruction("-","MINUS_CHAR");
		codeGen.writeInstruction("*","MINUS_ONE_INTERNAL");
		codeGen.writeInstruction("JN","MR_START");
		codeGen.writeInstruction("LV","=1");
		codeGen.writeInstruction("MM","IS_NEGATIVE");
		codeGen.writeInstruction("LD","LOW_BYTE");
		codeGen.writeInstruction("SC","UPDATE_CONVERTED");
		codeGen.setLabel("LOOP_READ");
		codeGen.writeInstruction("GD","/000");
		codeGen.writeInstruction("MM","BYTE_READ");
		codeGen.writeInstruction("SC","SPLIT_WORD");
		codeGen.setLabel("MR_START");
		codeGen.writeInstruction("LD","HIGH_BYTE");
		codeGen.writeInstruction("SC","UPDATE_CONVERTED");
		codeGen.writeInstruction("LD","LOW_BYTE");
		codeGen.writeInstruction("SC","UPDATE_CONVERTED");
		codeGen.writeInstruction("JP","LOOP_READ");
		codeGen.setLabel("FINISH_READ");
		codeGen.writeInstruction("LD","IS_NEGATIVE");
		codeGen.writeInstruction("JZ","RETURN_READ");
		codeGen.writeInstruction("LD","CONVERTED_VALUE");
		codeGen.writeInstruction("*","MINUS_ONE_INTERNAL");
		codeGen.writeInstruction("RS","MVN_READ");
		codeGen.setLabel("RETURN_READ");
		codeGen.writeInstruction("LD","CONVERTED_VALUE");
		codeGen.writeInstruction("RS","MVN_READ");
		codeGen.setLabel("UPDATE_CONVERTED");
		codeGen.writeInstruction("K", "/0");
		codeGen.writeInstruction("MM","BYTE_READ");
		codeGen.writeInstruction("LV","/00A");
		codeGen.writeInstruction("-","BYTE_READ");
		codeGen.writeInstruction("JZ","FINISH_READ");
		codeGen.writeInstruction("LV","/00D");
		codeGen.writeInstruction("-","BYTE_READ");
		codeGen.writeInstruction("JZ","FINISH_READ");
		codeGen.writeInstruction("LV","=10");
		codeGen.writeInstruction("*","CONVERTED_VALUE");
		codeGen.writeInstruction("MM","CONVERTED_VALUE");
		codeGen.writeInstruction("SC","ASCII_TO_INT");
		codeGen.writeInstruction("+","CONVERTED_VALUE");
		codeGen.writeInstruction("MM","CONVERTED_VALUE");
		codeGen.writeInstruction("RS","UPDATE_CONVERTED");
		codeGen.setLabel("SPLIT_WORD");
		codeGen.writeInstruction("K", "/0000");
		codeGen.writeInstruction("/","SHIFT_TWO");
		codeGen.writeInstruction("MM","HIGH_BYTE");
		codeGen.writeInstruction("LD","BYTE_READ");
		codeGen.writeInstruction("*","SHIFT_TWO");
		codeGen.writeInstruction("/","SHIFT_TWO");
		codeGen.writeInstruction("MM","LOW_BYTE");
		codeGen.writeInstruction("RS","SPLIT_WORD");
		codeGen.setLabel("INT_VALUE");
		codeGen.writeVariable("K", "=0000");
		codeGen.setLabel("ASCII_ZERO");
		codeGen.writeVariable("K", "=48");
		codeGen.setLabel("NINE");
		codeGen.writeVariable("K", "=9");
		codeGen.setLabel("ASCII_TO_INT");
		codeGen.writeInstruction("K", "/0000");
		codeGen.writeInstruction("LV","=0");
		codeGen.writeInstruction("MM","INT_VALUE");
		codeGen.writeInstruction("LD","BYTE_READ");
		codeGen.writeInstruction("-","ASCII_ZERO");
		codeGen.writeInstruction("MM","INT_VALUE");
		codeGen.writeInstruction("JN","ERRO_ASCII_TO_INT");
		codeGen.writeInstruction("LD","NINE");
		codeGen.writeInstruction("-","INT_VALUE");
		codeGen.writeInstruction("JN","ERRO_ASCII_TO_INT");
		codeGen.writeInstruction("LD","INT_VALUE");
		codeGen.writeInstruction("RS","ASCII_TO_INT");
		codeGen.setLabel("ERRO_ASCII_TO_INT");
		codeGen.writeInstruction("LV","=0");
		codeGen.writeInstruction("RS","ASCII_TO_INT");
		codeGen.setLabel("RESTO_DIVISAO");
		codeGen.writeVariable("K", "=0");
		codeGen.setLabel("QUOTIENT");
		codeGen.writeVariable("K", "=0");
		codeGen.setLabel("TEN");
		codeGen.writeVariable("K", "=10");
		codeGen.setLabel("QUOTIENT_TIMES_POW");
		codeGen.writeVariable("K", "=0");
		codeGen.setLabel("MINUS_ONE_INTERNAL");
		codeGen.writeVariable("K", "/FFFF");
		codeGen.setLabel("POW");
		codeGen.writeVariable("K", "=0");
		codeGen.setLabel("MVN_PRINT");
		codeGen.writeInstruction("K", "/0000");
		codeGen.writeInstruction("MM","INT_VALUE");
		codeGen.writeInstruction("JZ","PRINT_ZERO");
		codeGen.writeInstruction("LV","=1");
		codeGen.writeInstruction("MM","POW");
		codeGen.writeInstruction("LD","INT_VALUE");
		codeGen.writeInstruction("*","MINUS_ONE_INTERNAL");
		codeGen.writeInstruction("JN","FIND_POW_LOOP");
		codeGen.writeInstruction("MM","INT_VALUE");
		codeGen.writeInstruction("LV","/2D");
		codeGen.writeInstruction("PD","/0100");
		codeGen.setLabel("FIND_POW_LOOP");
		codeGen.writeInstruction("LD","INT_VALUE");
		codeGen.writeInstruction("-","POW");
		codeGen.writeInstruction("JZ","LOOP_IMPRESSAO");
		codeGen.writeInstruction("JN","END_FIND_POW");
		codeGen.writeInstruction("LD","POW");
		codeGen.writeInstruction("*","TEN");
		codeGen.writeInstruction("MM","POW");
		codeGen.writeInstruction("JP","FIND_POW_LOOP");
		codeGen.setLabel("END_FIND_POW");
		codeGen.writeInstruction("LD","POW");
		codeGen.writeInstruction("/","TEN");
		codeGen.writeInstruction("MM","POW");
		codeGen.setLabel("LOOP_IMPRESSAO");
		codeGen.writeInstruction("LD","INT_VALUE");
		codeGen.writeInstruction("/","POW");
		codeGen.writeInstruction("MM","QUOTIENT");
		codeGen.writeInstruction("*","POW");
		codeGen.writeInstruction("MM","QUOTIENT_TIMES_POW");
		codeGen.writeInstruction("LD","INT_VALUE");
		codeGen.writeInstruction("-","QUOTIENT_TIMES_POW");
		codeGen.writeInstruction("MM","INT_VALUE");
		codeGen.writeInstruction("LD","QUOTIENT");
		codeGen.writeInstruction("+","ASCII_ZERO");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LD","POW");
		codeGen.writeInstruction("/","TEN");
		codeGen.writeInstruction("MM","POW");
		codeGen.writeInstruction("*","MINUS_ONE_INTERNAL");
		codeGen.writeInstruction("JN","LOOP_IMPRESSAO");
		codeGen.writeInstruction("RS","MVN_PRINT");
		codeGen.setLabel("PRINT_ZERO");
		codeGen.writeInstruction("LV","/30");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("RS","MVN_PRINT");
		codeGen.setLabel("MVN_PRINTC");
		codeGen.writeInstruction("K", "/0000");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("RS","MVN_PRINTC");
		codeGen.setLabel("MVN_PRINTB");
		codeGen.writeInstruction("K", "/0000");
		codeGen.writeInstruction("JZ","PRINTB_FALSE");
		codeGen.writeInstruction("LV","/46");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/41");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/4C");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/53");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/45");
		codeGen.writeInstruction("PD","/0100");
		codeGen.setLabel("PRINTB_FALSE");
		codeGen.writeInstruction("LV","/54");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/52");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/55");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("LV","/45");
		codeGen.writeInstruction("PD","/0100");
		codeGen.writeInstruction("RS","MVN_PRINTB");
		
	}

}
